package org.indolphin.platform.auth.service.impl;

import org.indolphin.platform.auth.mapper.MenuMapper;
import org.indolphin.platform.auth.mapper.RoleMapper;
import org.indolphin.platform.auth.service.MenuService;
import org.indolphin.platform.common.entity.Menu;
import org.indolphin.platform.common.entity.Role;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class MenuServiceImpl implements MenuService {

    @Resource
    private RoleMapper roleMapper;

    @Resource
    private MenuMapper menuMapper;

    @Override
    public List<Menu> queryMenuList() {

        // 获取当前登录用户标识
        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();

        // 查询用户角色列表
        List<Role> roles = roleMapper.queryUserRoles(principal.toString());

        // 查询角色关联的菜单
        return menuMapper.queryMenuList(roles);
    }
}
